From 7cdf0f64076d05bab8edaac9aa02ddfef510afb5 Mon Sep 17 00:00:00 2001 From: "smh22@firebug.cl.cam.ac.uk" Date: Mon, 21 Nov 2005 16:40:16 +0100 Subject: [PATCH] Fix 'belt + braces' check in xc_linux_save and improve error handling for live migrate (this includes making shadow enable idempotent). Signed-off-by: Steven Hand --- tools/libxc/xc_linux_save.c | 12 ++++++++++-- tools/libxc/xg_save_restore.h | 6 ++++++ xen/arch/x86/shadow32.c | 6 +++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/tools/libxc/xc_linux_save.c b/tools/libxc/xc_linux_save.c index 54cdb2ce15..0863ac6675 100644 --- a/tools/libxc/xc_linux_save.c +++ b/tools/libxc/xc_linux_save.c @@ -798,6 +798,7 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters, pfn_batch = calloc(MAX_BATCH_SIZE, sizeof(unsigned long)); if ((pfn_type == NULL) || (pfn_batch == NULL)) { + ERR("failed to alloc memory for pfn_type and/or pfn_batch arays."); errno = ENOMEM; goto out; } @@ -817,7 +818,7 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters, for (i = 0; i < max_pfn; i++) { mfn = live_p2m[i]; - if((live_m2p[mfn] != i) && (mfn != 0xffffffffUL)) { + if((mfn != 0xffffffffUL) && (live_m2p[mfn] != i)) { DPRINTF("i=0x%x mfn=%lx live_m2p=%lx\n", i, mfn, live_m2p[mfn]); err++; @@ -912,7 +913,7 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters, unless its sent sooner anyhow */ set_bit(n, to_fix); - if(iter > 1) + if( (iter > 1) && IS_REAL_PFN(n) ) DPRINTF("netbuf race: iter %d, pfn %x. mfn %lx\n", iter, n, pfn_type[batch]); continue; @@ -1157,6 +1158,13 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters, out: + if (live) { + if(xc_shadow_control(xc_handle, dom, DOM0_SHADOW_CONTROL_OP_OFF, + NULL, 0, NULL ) < 0) { + DPRINTF("Warning - couldn't disable shadow mode"); + } + } + if (live_shinfo) munmap(live_shinfo, PAGE_SIZE); diff --git a/tools/libxc/xg_save_restore.h b/tools/libxc/xg_save_restore.h index d4eba303c3..c735deab41 100644 --- a/tools/libxc/xg_save_restore.h +++ b/tools/libxc/xg_save_restore.h @@ -125,6 +125,12 @@ static int get_platform_info(int xc_handle, uint32_t dom, /* Number of entries in the pfn_to_mfn_frame_list_list */ #define P2M_FLL_ENTRIES (((max_pfn)+(ulpp*ulpp)-1)/(ulpp*ulpp)) +/* Current guests allow 8MB 'slack' in their P2M */ +#define NR_SLACK_ENTRIES ((8 * 1024 * 1024) / PAGE_SIZE) + +/* Is the given PFN within the 'slack' region at the top of the P2M? */ +#define IS_REAL_PFN(_pfn) ((max_pfn - (_pfn)) > NR_SLACK_ENTRIES) + /* Returns TRUE if the PFN is currently mapped */ #define is_mapped(pfn_type) (!((pfn_type) & 0x80000000UL)) diff --git a/xen/arch/x86/shadow32.c b/xen/arch/x86/shadow32.c index e3a5389843..91c0e2dc5c 100644 --- a/xen/arch/x86/shadow32.c +++ b/xen/arch/x86/shadow32.c @@ -920,9 +920,9 @@ int __shadow_mode_enable(struct domain *d, unsigned int mode) struct vcpu *v; int new_modes = (mode & ~d->arch.shadow_mode); - // Gotta be adding something to call this function. - ASSERT(new_modes); - + if(!new_modes) /* Nothing to do - return success */ + return 0; + // can't take anything away by calling this function. ASSERT(!(d->arch.shadow_mode & ~mode)); -- 2.30.2